home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
lcppb.zip
/
LCPPANS.ZIP
/
PUTLN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-08
|
2KB
|
80 lines
// putln.cpp -- Add putln function to cwindow class
#include <iostream.h>
#include <dos.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
#include "window.h"
class cwindow2 : public cwindow {
private:
int yline;
public:
cwindow2() : cwindow()
{ yline = 0; }
cwindow2(winStruct &ws, const char *title) : cwindow(ws, title)
{ yline = 0; }
void putln(char *s);
void gotorc(int row, int col);
};
void fillBuffer(char *buf);
main()
{
winStruct ws = { 4, 44, 31, 18, 0x07, 0x1f, 0x70, 3 };
cwindow2 *theWindow;
char buffer[80];
cwindow::startup();
theWindow = new cwindow2(ws, " Scrolling Window ");
theWindow->showWindow();
while (!kbhit()) {
fillBuffer(buffer);
theWindow->putln(buffer);
delay(125); // Remove this line for top speed
}
cwindow::shutDown();
}
/* Write string and perform carriage return, line feed */
void cwindow2::putln(char *s)
{
winStruct ws;
puts(s);
ws = getInfo();
int n = ws.height - 2;
if (yline > n) yline = n;
if (yline == n) {
scrollUp(1);
gotorc(yline, 0);
eeol();
} else
gotorc(++yline, 0);
}
/* -- Replacement gotorc function */
void cwindow2::gotorc(int row, int col)
{
yline = row;
cwindow::gotorc(row, col);
}
/* -- Fill character buffer with random letters */
void fillBuffer(char *buf)
{
for (int i = 0; i <= 20; i++)
buf[i] = 'a' + (rand() % 26);
buf[i] = 0;
}
// Copyright (c) 1990 by Tom Swan. All rights reserved
// Revision 1.00 Date: 12/05/1990 Time: 06:10 pm
// Revision 1.01 Date: 07/08/1991 Time: 05:41 pm
// Converted for Borland C++ 2.0